{% extends "base.html" %}

{% block content %}
    <div class="card card-pretty">
        <div class="card-body">
            <div class="d-flex justify-content-between align-items-start mb-2">
                        <div>
                            <a class="btn btn-outline-secondary btn-sm mb-2" href="{{ request.headers.get('Referer','/') }}">← 返回</a>
                            <h3 class="card-title">{{ meeting.title }}</h3>
                            <p class="text-muted mb-0">作者：{{ meeting.author.username if meeting.author else '未知' }}</p>
                            <p class="text-muted small">创建时间：{{ meeting.created_at.strftime('%Y-%m-%d %H:%M') }}</p>
                        </div>
                        <div>
                            {% if user.is_admin or meeting.created_by == user.id %}
                                <div class="d-flex gap-2">
                                    <a class="btn btn-secondary" href="/meetings/{{ meeting.id }}/edit">编辑</a>
                                    <form method="post" action="/meetings/{{ meeting.id }}/delete">
                                        <button class="btn btn-danger" type="submit" onclick="return confirm('确定删除该记录？')">删除</button>
                                    </form>
                                </div>
                            {% endif %}
                        </div>
                    </div>

            <hr>
            <h5>会议详情</h5>
            <div class="mt-2">
                <div class="row">
                    <div class="col-md-6">
                        <p><strong>会议时间：</strong> {{ get_field(meeting, content, 'meeting_time', '会议时间') }}</p>
                        <p><strong>会议地点：</strong> {{ get_field(meeting, content, 'location', '会议地点') }}</p>
                    </div>
                    <div class="col-md-6">
                        <p><strong>参会人员：</strong>
                            {% set p = get_field(meeting, content, 'participants', '参会人员') %}
                            {{ format_participants(p) }}
                        </p>
                    </div>
                </div>

                <hr>
                <h6>会议纪要</h6>
                <div class="mb-3">
                    {% set mm = meeting.minutes or content.get('minutes') or content.get('会议纪要') %}
                    {% if mm %}
                        <pre class="bg-light p-3 rounded">{{ mm }}</pre>
                    {% else %}
                        <div class="text-muted">无会议纪要</div>
                    {% endif %}
                </div>

                <h6>待办事项</h6>
                <div class="mb-3">
                    {% set todo_raw = meeting.todos or content.get('todos') or content.get('待办事项') %}
                    {% if todo_raw %}
                        {% if '\n' in todo_raw %}
                            <ul>
                                {% for it in todo_raw.split('\n') if it.strip() %}
                                    <li>{{ it }}</li>
                                {% endfor %}
                            </ul>
                        {% elif todo_raw is mapping %}
                            <pre>{{ todo_raw | tojson(indent=2) }}</pre>
                        {% else %}
                            <p>{{ todo_raw }}</p>
                        {% endif %}
                    {% else %}
                        <div class="text-muted">无待办事项</div>
                    {% endif %}
                </div>
            </div>

            <div class="mt-3">
                {% if attachments %}
                    <h6>附件</h6>
                    <ul>
                        {% for a in parse_attachments(attachments) %}
                            {% if a is mapping %}
                                <li>
                                    <a href="/uploads/{{ a.saved_name }}" target="_blank">{{ a.orig_name or a.saved_name }}</a>
                                    {% if a.remark %}
                                        <div class="text-muted small">备注：{{ a.remark }}</div>
                                    {% endif %}
                                </li>
                            {% else %}
                                <li><a href="/uploads/{{ a }}" target="_blank">{{ a }}</a></li>
                            {% endif %}
                        {% endfor %}
                    </ul>
                {% endif %}

                <a class="btn btn-secondary" href="{{ request.headers.get('Referer','/') }}">返回列表</a>
            </div>
        </div>
    </div>
{% endblock %}
